import {
  Body,
  Inject,
  Post,
  Provide,
  ALL,
  Get,
  Query,
} from '@midwayjs/decorator';
import { CoolController, BaseController } from '@cool-midway/core';
import { GoodsInfoEntity } from '../../entity/info';
import { GoodsInfoService } from '../../service/info';
import { Context } from 'egg';
import { CreateApiDoc } from '@midwayjs/swagger/dist/lib/createAPI';

/**
 * 描述
 */
@Provide()
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: GoodsInfoEntity,
  service: GoodsInfoService,
})
export class GoodsInfoController extends BaseController {
  @Inject()
  goodsInfoService: GoodsInfoService;

  
  @Inject()
  ctx: Context;

  @Post('/search')
  async search(@Body(ALL) query: any) {
    return this.ok(await this.goodsInfoService.search(query));
  }

  @Get('/lists')
  async lists(@Query(ALL) query: any) {
    return this.ok(await this.goodsInfoService.lists(query.ids.split('_')));
  }

  @CreateApiDoc()
    .summary('用户的创建设计作品')
    .param('id', { required: true })
    .param('designPic')
    .param('originalId')
    .respond(200)
    .build()
  @Post('/create')
  async create(@Body(ALL) query: any) {
    let {id , designPic ,originalId} =query
    let goods = await this.goodsInfoService.info(id)
    
    delete goods.id
    delete goods.createTime
    delete goods.updateTime
    goods.originalId=originalId
    goods.designPic=designPic
    goods.userId=this.ctx.user.id
    goods.salesType=2
    goods.status=2

    return this.ok(await this.goodsInfoService.add(goods));
  }
}
